
#include "Random.h"
#include <time.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

void Random::initSeed(){
    pthread_mutex_lock(&randLocker);
    if(!isSeeded){
        srand(time(NULL));
        isSeeded = true;
    }
    pthread_mutex_unlock(&randLocker);
}

int Random::getRandomNum(int upperLimit){
    pthread_mutex_lock(&randLocker);
    int randomNum = (rand() % upperLimit);
    pthread_mutex_unlock(&randLocker);
    return randomNum;
}

pthread_mutex_t Random::randLocker;
bool Random::isSeeded = false;